package com.PAT.UnSatisfying;
import java.util.*;
/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zjz
 * @Date: 2021/12/16/9:16
 * @Description: 差2
 * @Target: C 代表“锤子”、J 代表“剪刀”、B 代表“布”,三种情况,胜负平, C>J>B>C
 */
public class 锤子剪刀布 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String numStr = in.nextLine();
        int num = Integer.valueOf(numStr);
        String[] ssStr = new String[num];
        int c = 0;
        while (c<num){
            String ss = in.nextLine();
            ssStr[c++] = ss;
        }

        int y = 0;
        int p = 0;
        int s = 0;
        int[] sum = new int[3];  // 用于0C,1B,2J计数
        int[] sum1 = new int[3];

        for (String sss : ssStr) {

            String[] ssArr = sss.split(" ");
            if (ssArr[0].equals(ssArr[1])){
               p++;
            }else if (GetWinOrFail(ssArr[0],ssArr[1])){
                if ("C".equals(ssArr[0])){
                    sum[0]++;
                }else if ("B".equals(ssArr[0])){
                    sum[1]++;
                }else if ("J".equals(ssArr[0])){
                    sum[2]++;
                }
                y++;
            }else{
                if ("C".equals(ssArr[1])){
                    sum1[0]++;
                }else if ("B".equals(ssArr[1])){
                    sum1[1]++;
                }else if ("J".equals(ssArr[1])){
                    sum1[2]++;
                }
                s++;
            }



        }


        System.out.println(y+" "+ p + " "+s);
        System.out.println(s+" "+ p + " "+y);
        if (sum[0]>sum[1]&&sum[0]>=sum[2]){
            System.out.print("C ");
        }else if (sum[1]>=sum[0]&&sum[1]>=sum[2]){
            System.out.print("B ");
        }else {
            System.out.print("J ");
        }
        if (sum1[0]>sum1[1]&&sum1[0]>=sum1[2]){
            System.out.print("C");
        }else if (sum1[1]>=sum1[0]&&sum1[1]>=sum1[2]){
            System.out.print("B");
        }else {
            System.out.print("J");
        }


    }


    public static void OutTest(String ss){
        String[] ssArr = ss.split(" ");
        if (ssArr[0].equals(ssArr[1])){
            System.out.println("平");
        }else if (GetWinOrFail(ssArr[0],ssArr[1])){
            System.out.println("赢");
        }else{
            System.out.println("输");
        }
    }


    public static boolean GetWinOrFail(String s1,String s2){
        boolean flag = false;

        String[] StrArray = new String[]{"C","J","B","C"};
        for (int i = 0; i < 4; i++) {
            if (s1.equals(StrArray[i])){
                if(i==3&&flag==false){
                    flag = false;
                }else if (i<3){
                    if (s2.equals(StrArray[i+1])){
                        flag = true;
                    }
                }
            }
        }

        return flag;
    }

}
